package cn.jlonely.xyhx.app.controller;

import cn.jlonely.xyhx.app.service.AppRankingService;
import cn.jlonely.xyhx.pojo.Comments;
import cn.jlonely.xyhx.pojo.Ranking;
import cn.jlonely.xyhx.pojo.vo.CommentsVo;
import cn.jlonely.xyhx.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/app")
public class AppRankingController {
    @Autowired
    private AppRankingService appRankingService;
    /**
     * 查找榜单
     * @param topic
     * @param id
     * @return
     */
    @GetMapping("/getRankingInfoAll")
    public Result getRankingInfo(Integer userId, String topic, Integer id) {
        List<Ranking> ranking = appRankingService.getRankingInfoAll(userId,topic,id);
        return  Result.success(ranking);
    }
    /**
     * 收藏
     */
    @PostMapping("/createFavorite")
    public Result createFavorite(Integer userId,Integer rankingId){
     appRankingService.createFavorite(userId,rankingId);
        return Result.success();
    }
    /**
     * 取消收藏
     */
    @DeleteMapping("/deleteFavorite")
    public Result deleteFavorite(Integer userId,Integer rankingId){
        appRankingService.deleteFavorite(userId,rankingId);
        return Result.success();
    }
    /**
     * 查询所有收藏
     */
    @GetMapping("/getFavoriteAll")
    public Result getFavoriteAll(Integer userId){
        List<Ranking> ranking = appRankingService.getFavoriteAll(userId);
        return Result.success(ranking);
    }

    /**
     * 参与投票记录
     */
    @GetMapping("/getHistoryAll")
    public Result getHistoryVitoAll(Integer userId){
       List<Ranking> ranking = appRankingService.getHistoryVitoAll(userId);
       return Result.success(ranking);
    }

    /**
     * 查询评论记录
     */
    @GetMapping("/getCommentsAll")
    public Result getCommentsAll(Integer rankingId){
        List<Comments> ranking = appRankingService.getCommentsAll(rankingId);
        return Result.success(ranking);
    }
    /**
     * 创建评论
     */
    @PostMapping("/createComments")
    public Result createComments(@RequestBody Comments comments){
        appRankingService.createComments(comments);
        return Result.success();
    }
    /**
     * 查看自己的历史评论
     */
    @GetMapping("/getHistoryComments")
    public Result getComments(Integer userId){
        List<CommentsVo> ranking = appRankingService.getHistoryComments(userId);
        return Result.success(ranking);
    }


}
